package com.example.yiwei.crm.view.Class;

import android.text.TextUtils;
import android.util.Log;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

/**
 * Created by Administrator on 2017/7/26.
 */

public class NetWorkUtil {
    public static String getCount(String url,String parms){
        String result = "";
        BufferedReader reader = null;
        String result1 = null;
        if (parms!=null){
            try {
                result1 = URLEncoder.encode(parms, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            Log.d("cccc",url);
            Log.d("cccc",result1);
        }

        try {
            URL mURL = null;
            if (parms!=null){
                 mURL=new URL(url+result1);
            }else {
                mURL=new URL(url);
            }

            HttpURLConnection conn=(HttpURLConnection) mURL.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(false);
            conn.setUseCaches(true);
            conn.setRequestMethod("GET");
//            if(!TextUtils.isEmpty(parms)){
//                StringBuffer buffter = new StringBuffer();
////                buffter.append("list=").append(parms);
//                conn.getOutputStream().write(buffter.toString().getBytes());
//            }
            reader=new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String len;
            while((len=reader.readLine())!=null){
                result = len;
            }
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally{
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return result;

    }
}
